package ch11_多线程与并发;

public class Repository {
	private boolean isEmpty = true;
	private int product;

	public synchronized void put(int product) {
		if (!isEmpty) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		this.product = product;
		this.isEmpty = false;
		System.out.print("Produce " + product);
		this.notify();
	}

	public synchronized void get() {
		if (isEmpty) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(",Consume " + this.product);
		this.isEmpty = true;
		this.notify();
	}
}
